package com.steak.system.util;

import com.steak.system.common.exception.BusinessException;
import com.steak.system.common.exception.EmBusinessError;
import com.steak.system.pojo.dataobject.RecruitDO;
import org.apache.commons.beanutils.BeanUtils;

import java.lang.reflect.InvocationTargetException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.SimpleFormatter;
import java.util.zip.DataFormatException;

public class ConvertUtils {
    /**
     * Dto转为Do
     * @param Dto
     * @param Do
     * @return  后转前
     * @throws BusinessException
     * @throws InvocationTargetException
     * @throws IllegalAccessException
     */
    public static Object DtoToDo(Object Do,Object Dto) throws BusinessException{
        if (Dto == null){
            throw new BusinessException(EmBusinessError.UNKNOWN_ERROR);
        }
        try {
            BeanUtils.copyProperties(Do,Dto);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        return Do;
    }

    /**
     * Do转为Dto
     * @param Do
     * @param Dto
     * @return
     * @throws BusinessException
     * @throws InvocationTargetException
     * @throws IllegalAccessException
     */
    public static Object DoToDto(Object Do,Object Dto){
        try {
            BeanUtils.copyProperties(Dto,Do);
        }catch (Exception e){
            e.printStackTrace();
        }
        return Dto;
    }

    public static Object DtoToDto(Object dto , Object dto2){
        try {
            BeanUtils.copyProperties(dto2,dto);
        }catch (Exception e){
            e.printStackTrace();
        }
        return dto2;
    }

    public static Object DtoToVo(Object dto , Object vo){
        try {
            BeanUtils.copyProperties(vo,dto);
        }catch (Exception e){
            e.printStackTrace();
        }
        return vo;
    }

    public static Date stringToDate(String s){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date = null;
        try {
            date = simpleDateFormat.parse(s);
        }catch (Exception e){
            e.printStackTrace();
        }
        return date;
    }

    public static String dateToString(Date date){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String s = simpleDateFormat.format(date);
        return s;
    }

    public static Date formatDate(Date date){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String s = simpleDateFormat.format(date);
        Date date1 = null;
        try {
            date1 = simpleDateFormat.parse(s);
        }catch (Exception e){
            e.printStackTrace();
        }
        return date1;
    }

}
